/*
* HexLabel.cpp
*
* Copyright(C) 2009, Лущик Павел aka nanoo
*
* This code is lisenced under the GPL version 2. For details see 
* LISENCE.txt
*/


#include"HexLabel.h"
void define_and_set_state(HexLabel*,int);

HexLabel::HexLabel(QWidget *parent): QLabel(parent)
{
	state=0x0;
	setFrameStyle(QFrame::Panel| QFrame::Sunken);
	go_up();
	setToolTip(tr("Use mouse wheel to change the value"));
}

void HexLabel::wheelEvent(QWheelEvent *ev)
{
	ev->accept();
	if(ev->delta()>0){
		go_up();
	} else {
		go_down();
	}
	emit wheel_is_running();
}

void HexLabel::go_up()
{
	state++;
	if(state>0xf){
		state=0x0;
		emit up();
	}
	define_and_set_state(this,state);
}

void HexLabel::go_down()
{
	state--;
	if(state<0x0){
		state=0xf;
		emit down();
	}
	define_and_set_state(this,state);
}

int HexLabel::value()
{
	return state;
}

void HexLabel::setValue(int a){
	if(a>=0||a<=0xf){
		state=a;
	}
	define_and_set_state(this,state);
}

void define_and_set_state(HexLabel* a, int state){
	switch(state){
		case 0x0: a->setText("<b>0</b>"); break;
		case 0x1: a->setText("<b>1</b>"); break;
		case 0x2: a->setText("<b>2</b>"); break;
		case 0x3: a->setText("<b>3</b>"); break;
		case 0x4: a->setText("<b>4</b>"); break;
		case 0x5: a->setText("<b>5</b>"); break;
		case 0x6: a->setText("<b>6</b>"); break;
		case 0x7: a->setText("<b>7</b>"); break;
		case 0x8: a->setText("<b>8</b>"); break;
		case 0x9: a->setText("<b>9</b>"); break;
		case 0xa: a->setText("<b>A</b>"); break;
		case 0xb: a->setText("<b>B</b>"); break;
		case 0xc: a->setText("<b>C</b>"); break;
		case 0xd: a->setText("<b>D</b>"); break;
		case 0xe: a->setText("<b>E</b>"); break;
		case 0xf: a->setText("<b>F</b>"); break;
	}
}
